package com.example.springboot.controller.rest;

import com.example.springboot.utils.HttpSourceUtil;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * 测试springboot开启基于rest风格api
 *
 * @Author:ChenZhangKun
 * @Date: 2021/6/8 17:02
 */
@RestController
public class RestControllerTest {
    /**
     * 查询
     *
     * @return
     */
    @RequestMapping(value = "/user11", method = RequestMethod.GET)
    public String getUser(HttpServletRequest request) {
        boolean mobileDevice = HttpSourceUtil.isMobileDevice(request);
        System.out.println((mobileDevice ? "请求来自手机端" : "请求来自电脑端"));
        boolean weChat = HttpSourceUtil.isWeChat(request);
        System.out.println(weChat ? "请求来自微信端" : "请求不是来自微信端");
        return "getUser";
    }

    /**
     * 删除
     *
     * @return
     */
    @RequestMapping(value = "/user11", method = RequestMethod.DELETE)
    public String deleteUser() {
        return "deleteUser";
    }

    /**
     * 修改
     *
     * @return
     */
    @RequestMapping(value = "/user11", method = RequestMethod.POST)
    public String updateUser() {
        return "postUser";
    }

    /**
     * 增加
     *
     * @return
     */
    @RequestMapping(value = "/user11", method = RequestMethod.PUT)
    public String addUser() {
        return "putUser";
    }
}
